package org.grow.common.controller;

import org.grow.common.exception.BillStateException;
import org.grow.common.exception.MissTargetException;
import org.grow.common.service.JwtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: xwg
 * @CreateDate: 2023/9/20
 */

@RestController
@RequestMapping("/jwt")
public class JwtController {
    @GetMapping("/exception1")
    public String exception1() {
        throw new BillStateException("表单已经提交了 不能再修改");
    }

    @GetMapping("/exception2")
    public String exception2() {
        throw new MissTargetException("目标没有找到");
    }

    @Autowired
    private JwtService jwtService;
    @PostMapping("/createTokenByUsername")
    public String createTokenByUsername(@RequestParam String username) {
        Map<String, Object> map = new HashMap<>();
        map.put("username", username);
        return jwtService.createToken(map);
    }

    @PostMapping("/parseToken")
    public Map<String, Object> parseToken(@RequestParam String token) {
        return jwtService.parseToken(token);
    }
}
